﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GestionEco;

namespace Ecosystème
{
    public partial class frmGestionEditeur : Form
    {
        private List<EtreVivant> evCourant;
        private bool InsertTerrain = false;
        private bool InsertEtre = false;
        private Terrain _terrain;
        public Terrain terrain
        {
            get { return _terrain; }
            set { _terrain = value; }
        }
        private bool _Full3DIso = false;
        public bool Full3DIso
        {
            get { return _Full3DIso; }
            set { _Full3DIso = value; }
        }


        private List<TypeEspece> _listtype;
        public List<TypeEspece> listtype
        {
            get { return _listtype; }
            set { _listtype = value; }
        }
        private Image _ImageEtre;
        public Image ImageEtre
        {
            get { return _ImageEtre; }
            set { _ImageEtre = value; }
        }
        private string _nomEtre;
        public string nomEtre
        {
            get { return _nomEtre; }
            set { _nomEtre = value; }
        }
        public frmGestionEditeur()
        {
            this.Location = new Point(0, 0);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            InitializeComponent();
            evCourant = new List<EtreVivant>();
            //Jeu.simulation();

        }

        private void btnRetour_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        //public IntPtr getDrawSurface()
        //{
        //    return this.pictSimu.Handle;
        //}

        private void frmPlateau_Load(object sender, EventArgs e)
        {
            System.Drawing.Image im = System.Drawing.Image.FromFile(Application.StartupPath + @"\Content\mer.jpg");
            Bitmap img = new Bitmap(im, new System.Drawing.Size(pbMer.Width, pbMer.Height));
            pbMer.BackgroundImage = img;
            im = System.Drawing.Image.FromFile(Application.StartupPath + @"\Content\Foret.jpg");
            img = new Bitmap(im, new System.Drawing.Size(pbForet.Width, pbForet.Height));
            pbForet.BackgroundImage = img;
            im = System.Drawing.Image.FromFile(Application.StartupPath + @"\Content\Plaine.jpg");
            img = new Bitmap(im, new System.Drawing.Size(pbPlaine.Width, pbPlaine.Height));
            pbPlaine.BackgroundImage = img;
            im = System.Drawing.Image.FromFile(Application.StartupPath + @"\Content\Montagne.jpg");
            img = new Bitmap(im, new System.Drawing.Size(pbMontagne.Width, pbMontagne.Height));
            pbMontagne.BackgroundImage = img;
            im = System.Drawing.Image.FromFile(Application.StartupPath + @"\Content\Desert.jpg");
            img = new Bitmap(im, new System.Drawing.Size(pbDesert.Width, pbDesert.Height));
            pbDesert.BackgroundImage = img;
            foreach (TypeEspece te in listtype)
            {
                img = new Bitmap(te.getImageEtre(),25,25);
                ImageConverter converter = new ImageConverter();
                ListeTypeEtreVivant.Rows.Add(te.getNomType(),(byte[])converter.ConvertTo(img, typeof(byte[])));
                
            }
        }

        private void pbMer_Click(object sender, EventArgs e)
        {
            if(InsertTerrain)
            terrain = new Terrain(10, 10, "Mer");
        }

        private void cbTerrain_CheckedChanged(object sender, EventArgs e)
        {
            if (!_Full3DIso)
            {
                InsertTerrain = cbTerrain.Checked;
                cbEtre.Checked = false;
                if (!InsertTerrain)
                {
                    terrain = null;
                }
            }
            else
            {
                cbTerrain.Checked = false;
                InsertTerrain = false;
            }
        }

        private void pbForet_Click(object sender, EventArgs e)
        {
            if (InsertTerrain)
            {
                Random rdm = new Random();
                int quantiteEau = rdm.Next(7, 10);
                terrain = new Terrain(quantiteEau, quantiteEau, "Forêt");
            }
        }

        private void pbPlaine_Click(object sender, EventArgs e)
        {
            if (InsertTerrain)
            {
                Random rdm = new Random();
                int quantiteEau = rdm.Next(4, 7);
                terrain = new Terrain(quantiteEau, quantiteEau, "Plaine");
            }
        }

        private void pbMontagne_Click(object sender, EventArgs e)
        {
            if (InsertTerrain)
            {
                Random rdm = new Random();
                int quantiteEau = rdm.Next(2, 5);
                terrain = new Terrain(quantiteEau, quantiteEau, "Montagne");
            }
        }

        private void pbDesert_Click(object sender, EventArgs e)
        {
            if (InsertTerrain)
            {
                Random rdm = new Random();
                int quantiteEau = rdm.Next(0, 2);
                terrain = new Terrain(quantiteEau, quantiteEau, "Désert");
            }
        }

        private void cb3DIso_CheckedChanged(object sender, EventArgs e)
        {
            _Full3DIso = cb3DIso.Checked;
            if (terrain != null)
            {
                terrain = null;
            }
            if (_ImageEtre != null)
            {
                _ImageEtre = null;
            }
            cbTerrain.Checked = false;
            cbEtre.Checked = false;
        }


        private void cbEtre_CheckedChanged(object sender, EventArgs e)
        {
            if (!_Full3DIso)
            {
                InsertEtre = cbEtre.Checked;
                cbTerrain.Checked = false;
                if (!InsertEtre)
                    ImageEtre = null;
            }
            else
            {
                InsertEtre = false;
                cbEtre.Checked = false;
            }
        }

        private void ListeTypeEtreVivant_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (InsertEtre)
            {
                if (ListeTypeEtreVivant.Rows[e.RowIndex].Cells["Type"].Value.ToString() == "Chèvre")
                {
                    ImageEtre = System.Drawing.Image.FromFile(Application.StartupPath + @"\Content\EtreVivants\Chevre.png");
                }
                if (ListeTypeEtreVivant.Rows[e.RowIndex].Cells["Type"].Value.ToString() == "Loup")
                {
                    ImageEtre = System.Drawing.Image.FromFile(Application.StartupPath + @"\Content\EtreVivants\Loup.png");
                }
                if (ListeTypeEtreVivant.Rows[e.RowIndex].Cells["Type"].Value.ToString() == "Pigeon")
                {
                    ImageEtre = System.Drawing.Image.FromFile(Application.StartupPath + @"\Content\EtreVivants\pigeon.png");
                }
                if (ListeTypeEtreVivant.Rows[e.RowIndex].Cells["Type"].Value.ToString() == "Requin")
                {
                    ImageEtre = System.Drawing.Image.FromFile(Application.StartupPath + @"\Content\EtreVivants\requin.png");
                }
                if (ListeTypeEtreVivant.Rows[e.RowIndex].Cells["Type"].Value.ToString() == "Tulipe")
                {
                    ImageEtre = System.Drawing.Image.FromFile(Application.StartupPath + @"\Content\EtreVivants\tulipe.png");
                }
                if (ListeTypeEtreVivant.Rows[e.RowIndex].Cells["Type"].Value.ToString() == "Cactus")
                {
                    ImageEtre = System.Drawing.Image.FromFile(Application.StartupPath + @"\Content\EtreVivants\cactus.png");
                }
                if (ListeTypeEtreVivant.Rows[e.RowIndex].Cells["Type"].Value.ToString() == "Chat de gouttière")
                {
                    ImageEtre = System.Drawing.Image.FromFile(Application.StartupPath + @"\Content\EtreVivants\chat.png");
                }
                if (ListeTypeEtreVivant.Rows[e.RowIndex].Cells["Type"].Value.ToString() == "Chien sauvage")
                {
                    ImageEtre = System.Drawing.Image.FromFile(Application.StartupPath + @"\Content\EtreVivants\chien.png");
                }
                if (ListeTypeEtreVivant.Rows[e.RowIndex].Cells["Type"].Value.ToString() == "Chameau")
                {
                    ImageEtre = System.Drawing.Image.FromFile(Application.StartupPath + @"\Content\EtreVivants\chameau.png");
                }
                nomEtre = ListeTypeEtreVivant.Rows[e.RowIndex].Cells["Type"].Value.ToString();
            }
        }

       
    

    }
}
